<!--
 * @Descripttion: 
 * @version: v1
 * @Author: Terry
 * @Date: 2020-06-05 10:22:26
 * @LastEditors: Terry
 * @LastEditTime: 2024-11-12 20:36:12
-->
<template>
    <div  class='h-88'>
    <el-card class="m-h-100">
      <el-form :model="searchForm" :inline="true" ref="test">
        <el-form-item :label="$t('platform.project.name')">
          <el-input
            v-model="searchForm.name"
            :placeholder="$t('platform.project.nameTips')"
            clearable
          ></el-input>
        </el-form-item>
        <el-button type="primary" @click="getList()">{{$t('platform.project.searchBtn')}}</el-button>
      </el-form>
      <tables ref="tables" :tableColumn="tableColumn" :formData="searchForm" @listData= "(data)=>list = data">
        <template #attendanceCount="{data}">
          {{ data.attendanceCount }} / {{ data.memberEntryCount }}
          <br />{{$t('platform.project.rate')}}：
          <span v-if="data.attendanceCount == 0 || data.memberEntryCount == 0"
            >0%</span
          >
          <span v-else>
            {{ Math.floor((data.attendanceCount / data.memberEntryCount) * 10000) / 100  }} %
          </span>
        </template>
        <template #operation="{data}">
          <el-button
            size="mini"
            type="text"
            @click="toProject(data.projectCode, data.corpCode, data.name)"
          >
          {{$t('platform.project.enterPrj')}}
          </el-button>
        </template>
        <template #error="{data}">
          <div v-if="!data.checkRule" class="text-gray">
            {{$t('platform.project.noPermissions')}}
          </div>
          <div v-else-if="!data.isSync" class="text-red">{{$t('platform.project.unjointed')}}</div>
          <div
            v-else
            style="cursor: pointer;"
            @click="toSyncDetail(data.projectCode, data.corpCode, data.name)"
          >
            <div v-if="data.errorSync.length == 0" class="text-success">
              {{$t('platform.project.normal')}}
            </div>
            <div v-else>
              <div v-for="(value, index) in data.errorSync" :key="index">
                <div v-if="value.worker != 0">
                  {{ value["name"] }}：{{$t('platform.project.member')}}
                  <strong class="text-red">{{ value.worker }}</strong>
                  {{$t('platform.project.memberTips')}}
                </div>
                <div v-if="value.attendance != 0">
                  {{ value["name"] }}：{{$t('platform.project.attendance')}}
                  <strong class="text-red">{{ value.attendance }}</strong>
                  {{$t('platform.project.errorTips')}}
                </div>
                <div v-if="value.team != 0">
                  {{ value["name"] }}：{{$t('platform.project.team')}}
                  <strong class="text-red">{{ value.team }}</strong> {{$t('platform.project.errorTips')}}
                </div>
              </div>
            </div>
          </div>
        </template>
      </tables>
    </el-card>
  </div>
</template>
<script>
import {  getCellData } from "../api/project"
export default {
  components: {
  },
  data() {
    return {
      searchForm: {},
      prjStatus: {},
      list: [],
      tabelTotal: 0,
      cellLoad: true,
      cellData: [],
      tableColumn: [
        {
          slotName: "corpName",
          label: this.$t('platform.project.corpName'),
        },
        {
          slotName: "code",
          label: this.$t('platform.project.code'),
          width:150,
        },
        {
          slotName: "name",
          label: this.$t('platform.project.name'),
        },
        {
          slotName: "linkMan",
          label: this.$t('platform.project.linkMan'),
          width:80,
        },
        {
          slotName: "linkPhone",
          label: this.$t('platform.project.linkPhone'),
          width:100,
        },
        {
          slotName: "teamCount",
          label: this.$t('platform.project.teamCount'),
          width:80,
        },
        {
          label: this.$t('platform.project.attendanceCount'),
          slotName: "attendanceCount",
        },
        {
          label: this.$t('platform.project.error'),
          slotName: "error",
          width: 200,
        },
        {
          label: this.$t('platform.project.enterPrj'),
          slotName: "operation",
          fixed: "right",
          width: 100,
        },
      ],
    };
  },

  methods: {
    getPageData() {
      this.getList();
    },
    // 获取列表
    getList() {
      this.$refs.tables.getList();
    },
    /**
     * [toPorject 跳转到项目]
     * @param  {[type]} cuuid [公司营业执照号码]
     * @param  {[type]} puuid [项目uuid]
     * @return {[type]}       [description]
     */
    toProject(puuid, corpCode, name) {
      this.toPage(puuid, corpCode, name, "modules");
    },
    toSyncDetail(puuid, corpCode, name) {
      this.toPage(puuid, corpCode, name, "governmentStatus");
    },
    toPage(puuid, corpCode, name, pageName) {
      sessionStorage.setItem("puuid", puuid);
      sessionStorage.setItem("corpCode", corpCode);
      sessionStorage.setItem("projectName", name);
      let routeUrl = this.$router.resolve({ name: pageName });
      window.open(routeUrl.href, "_blank");
    },
    expandChange(row) {
      this.cellLoad = true;
      getCellData({ projectCode: row.projectCode })
        .then((res) => {
          this.cellData = res.data;
        })
        .finally((res) => {
        this.cellLoad = false;
        });
    },
  },
  mounted() {
    this.getPageData()
  },
};
</script>